<?php


abstract class BaseTabOrdenes extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $num_orden;


	
	protected $cf_tipo_orden;


	
	protected $cf_estudiante;


	
	protected $nacionalidad;


	
	protected $cf_carrera;


	
	protected $cf_decanato;


	
	protected $cf_semestre;


	
	protected $cf_ente;


	
	protected $fecha;


	
	protected $observaciones;


	
	protected $fecha_emision;


	
	protected $cf_grupo;


	
	protected $cf_usuario;


	
	protected $estatus;

	
	protected $collTabDetallesOrdens;

	
	protected $lastTabDetallesOrdenCriteria = null;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getNumOrden()
	{

		return $this->num_orden;
	}

	
	public function getCfTipoOrden()
	{

		return $this->cf_tipo_orden;
	}

	
	public function getCfEstudiante()
	{

		return $this->cf_estudiante;
	}

	
	public function getNacionalidad()
	{

		return $this->nacionalidad;
	}

	
	public function getCfCarrera()
	{

		return $this->cf_carrera;
	}

	
	public function getCfDecanato()
	{

		return $this->cf_decanato;
	}

	
	public function getCfSemestre()
	{

		return $this->cf_semestre;
	}

	
	public function getCfEnte()
	{

		return $this->cf_ente;
	}

	
	public function getFecha($format = 'Y-m-d')
	{

		if ($this->fecha === null || $this->fecha === '') {
			return null;
		} elseif (!is_int($this->fecha)) {
						$ts = strtotime($this->fecha);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [fecha] as date/time value: " . var_export($this->fecha, true));
			}
		} else {
			$ts = $this->fecha;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getObservaciones()
	{

		return $this->observaciones;
	}

	
	public function getFechaEmision($format = 'Y-m-d')
	{

		if ($this->fecha_emision === null || $this->fecha_emision === '') {
			return null;
		} elseif (!is_int($this->fecha_emision)) {
						$ts = strtotime($this->fecha_emision);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [fecha_emision] as date/time value: " . var_export($this->fecha_emision, true));
			}
		} else {
			$ts = $this->fecha_emision;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getCfGrupo()
	{

		return $this->cf_grupo;
	}

	
	public function getCfUsuario()
	{

		return $this->cf_usuario;
	}

	
	public function getEstatus()
	{

		return $this->estatus;
	}

	
	public function setNumOrden($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->num_orden !== $v) {
			$this->num_orden = $v;
			$this->modifiedColumns[] = TabOrdenesPeer::NUM_ORDEN;
		}

	} 
	
	public function setCfTipoOrden($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->cf_tipo_orden !== $v) {
			$this->cf_tipo_orden = $v;
			$this->modifiedColumns[] = TabOrdenesPeer::CF_TIPO_ORDEN;
		}

	} 
	
	public function setCfEstudiante($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->cf_estudiante !== $v) {
			$this->cf_estudiante = $v;
			$this->modifiedColumns[] = TabOrdenesPeer::CF_ESTUDIANTE;
		}

	} 
	
	public function setNacionalidad($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->nacionalidad !== $v) {
			$this->nacionalidad = $v;
			$this->modifiedColumns[] = TabOrdenesPeer::NACIONALIDAD;
		}

	} 
	
	public function setCfCarrera($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->cf_carrera !== $v) {
			$this->cf_carrera = $v;
			$this->modifiedColumns[] = TabOrdenesPeer::CF_CARRERA;
		}

	} 
	
	public function setCfDecanato($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->cf_decanato !== $v) {
			$this->cf_decanato = $v;
			$this->modifiedColumns[] = TabOrdenesPeer::CF_DECANATO;
		}

	} 
	
	public function setCfSemestre($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->cf_semestre !== $v) {
			$this->cf_semestre = $v;
			$this->modifiedColumns[] = TabOrdenesPeer::CF_SEMESTRE;
		}

	} 
	
	public function setCfEnte($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->cf_ente !== $v) {
			$this->cf_ente = $v;
			$this->modifiedColumns[] = TabOrdenesPeer::CF_ENTE;
		}

	} 
	
	public function setFecha($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [fecha] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->fecha !== $ts) {
			$this->fecha = $ts;
			$this->modifiedColumns[] = TabOrdenesPeer::FECHA;
		}

	} 
	
	public function setObservaciones($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->observaciones !== $v) {
			$this->observaciones = $v;
			$this->modifiedColumns[] = TabOrdenesPeer::OBSERVACIONES;
		}

	} 
	
	public function setFechaEmision($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [fecha_emision] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->fecha_emision !== $ts) {
			$this->fecha_emision = $ts;
			$this->modifiedColumns[] = TabOrdenesPeer::FECHA_EMISION;
		}

	} 
	
	public function setCfGrupo($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->cf_grupo !== $v) {
			$this->cf_grupo = $v;
			$this->modifiedColumns[] = TabOrdenesPeer::CF_GRUPO;
		}

	} 
	
	public function setCfUsuario($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->cf_usuario !== $v) {
			$this->cf_usuario = $v;
			$this->modifiedColumns[] = TabOrdenesPeer::CF_USUARIO;
		}

	} 
	
	public function setEstatus($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->estatus !== $v) {
			$this->estatus = $v;
			$this->modifiedColumns[] = TabOrdenesPeer::ESTATUS;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->num_orden = $rs->getString($startcol + 0);

			$this->cf_tipo_orden = $rs->getString($startcol + 1);

			$this->cf_estudiante = $rs->getString($startcol + 2);

			$this->nacionalidad = $rs->getString($startcol + 3);

			$this->cf_carrera = $rs->getString($startcol + 4);

			$this->cf_decanato = $rs->getString($startcol + 5);

			$this->cf_semestre = $rs->getString($startcol + 6);

			$this->cf_ente = $rs->getString($startcol + 7);

			$this->fecha = $rs->getDate($startcol + 8, null);

			$this->observaciones = $rs->getString($startcol + 9);

			$this->fecha_emision = $rs->getDate($startcol + 10, null);

			$this->cf_grupo = $rs->getString($startcol + 11);

			$this->cf_usuario = $rs->getString($startcol + 12);

			$this->estatus = $rs->getString($startcol + 13);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 14; 
		} catch (Exception $e) {
			throw new PropelException("Error populating TabOrdenes object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(TabOrdenesPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			TabOrdenesPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(TabOrdenesPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = TabOrdenesPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setNumOrden($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += TabOrdenesPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			if ($this->collTabDetallesOrdens !== null) {
				foreach($this->collTabDetallesOrdens as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


			if (($retval = TabOrdenesPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}


				if ($this->collTabDetallesOrdens !== null) {
					foreach($this->collTabDetallesOrdens as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}


			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = TabOrdenesPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getNumOrden();
				break;
			case 1:
				return $this->getCfTipoOrden();
				break;
			case 2:
				return $this->getCfEstudiante();
				break;
			case 3:
				return $this->getNacionalidad();
				break;
			case 4:
				return $this->getCfCarrera();
				break;
			case 5:
				return $this->getCfDecanato();
				break;
			case 6:
				return $this->getCfSemestre();
				break;
			case 7:
				return $this->getCfEnte();
				break;
			case 8:
				return $this->getFecha();
				break;
			case 9:
				return $this->getObservaciones();
				break;
			case 10:
				return $this->getFechaEmision();
				break;
			case 11:
				return $this->getCfGrupo();
				break;
			case 12:
				return $this->getCfUsuario();
				break;
			case 13:
				return $this->getEstatus();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = TabOrdenesPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getNumOrden(),
			$keys[1] => $this->getCfTipoOrden(),
			$keys[2] => $this->getCfEstudiante(),
			$keys[3] => $this->getNacionalidad(),
			$keys[4] => $this->getCfCarrera(),
			$keys[5] => $this->getCfDecanato(),
			$keys[6] => $this->getCfSemestre(),
			$keys[7] => $this->getCfEnte(),
			$keys[8] => $this->getFecha(),
			$keys[9] => $this->getObservaciones(),
			$keys[10] => $this->getFechaEmision(),
			$keys[11] => $this->getCfGrupo(),
			$keys[12] => $this->getCfUsuario(),
			$keys[13] => $this->getEstatus(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = TabOrdenesPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setNumOrden($value);
				break;
			case 1:
				$this->setCfTipoOrden($value);
				break;
			case 2:
				$this->setCfEstudiante($value);
				break;
			case 3:
				$this->setNacionalidad($value);
				break;
			case 4:
				$this->setCfCarrera($value);
				break;
			case 5:
				$this->setCfDecanato($value);
				break;
			case 6:
				$this->setCfSemestre($value);
				break;
			case 7:
				$this->setCfEnte($value);
				break;
			case 8:
				$this->setFecha($value);
				break;
			case 9:
				$this->setObservaciones($value);
				break;
			case 10:
				$this->setFechaEmision($value);
				break;
			case 11:
				$this->setCfGrupo($value);
				break;
			case 12:
				$this->setCfUsuario($value);
				break;
			case 13:
				$this->setEstatus($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = TabOrdenesPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setNumOrden($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setCfTipoOrden($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setCfEstudiante($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setNacionalidad($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setCfCarrera($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setCfDecanato($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setCfSemestre($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setCfEnte($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setFecha($arr[$keys[8]]);
		if (array_key_exists($keys[9], $arr)) $this->setObservaciones($arr[$keys[9]]);
		if (array_key_exists($keys[10], $arr)) $this->setFechaEmision($arr[$keys[10]]);
		if (array_key_exists($keys[11], $arr)) $this->setCfGrupo($arr[$keys[11]]);
		if (array_key_exists($keys[12], $arr)) $this->setCfUsuario($arr[$keys[12]]);
		if (array_key_exists($keys[13], $arr)) $this->setEstatus($arr[$keys[13]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(TabOrdenesPeer::DATABASE_NAME);

		if ($this->isColumnModified(TabOrdenesPeer::NUM_ORDEN)) $criteria->add(TabOrdenesPeer::NUM_ORDEN, $this->num_orden);
		if ($this->isColumnModified(TabOrdenesPeer::CF_TIPO_ORDEN)) $criteria->add(TabOrdenesPeer::CF_TIPO_ORDEN, $this->cf_tipo_orden);
		if ($this->isColumnModified(TabOrdenesPeer::CF_ESTUDIANTE)) $criteria->add(TabOrdenesPeer::CF_ESTUDIANTE, $this->cf_estudiante);
		if ($this->isColumnModified(TabOrdenesPeer::NACIONALIDAD)) $criteria->add(TabOrdenesPeer::NACIONALIDAD, $this->nacionalidad);
		if ($this->isColumnModified(TabOrdenesPeer::CF_CARRERA)) $criteria->add(TabOrdenesPeer::CF_CARRERA, $this->cf_carrera);
		if ($this->isColumnModified(TabOrdenesPeer::CF_DECANATO)) $criteria->add(TabOrdenesPeer::CF_DECANATO, $this->cf_decanato);
		if ($this->isColumnModified(TabOrdenesPeer::CF_SEMESTRE)) $criteria->add(TabOrdenesPeer::CF_SEMESTRE, $this->cf_semestre);
		if ($this->isColumnModified(TabOrdenesPeer::CF_ENTE)) $criteria->add(TabOrdenesPeer::CF_ENTE, $this->cf_ente);
		if ($this->isColumnModified(TabOrdenesPeer::FECHA)) $criteria->add(TabOrdenesPeer::FECHA, $this->fecha);
		if ($this->isColumnModified(TabOrdenesPeer::OBSERVACIONES)) $criteria->add(TabOrdenesPeer::OBSERVACIONES, $this->observaciones);
		if ($this->isColumnModified(TabOrdenesPeer::FECHA_EMISION)) $criteria->add(TabOrdenesPeer::FECHA_EMISION, $this->fecha_emision);
		if ($this->isColumnModified(TabOrdenesPeer::CF_GRUPO)) $criteria->add(TabOrdenesPeer::CF_GRUPO, $this->cf_grupo);
		if ($this->isColumnModified(TabOrdenesPeer::CF_USUARIO)) $criteria->add(TabOrdenesPeer::CF_USUARIO, $this->cf_usuario);
		if ($this->isColumnModified(TabOrdenesPeer::ESTATUS)) $criteria->add(TabOrdenesPeer::ESTATUS, $this->estatus);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(TabOrdenesPeer::DATABASE_NAME);

		$criteria->add(TabOrdenesPeer::NUM_ORDEN, $this->num_orden);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getNumOrden();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setNumOrden($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setCfTipoOrden($this->cf_tipo_orden);

		$copyObj->setCfEstudiante($this->cf_estudiante);

		$copyObj->setNacionalidad($this->nacionalidad);

		$copyObj->setCfCarrera($this->cf_carrera);

		$copyObj->setCfDecanato($this->cf_decanato);

		$copyObj->setCfSemestre($this->cf_semestre);

		$copyObj->setCfEnte($this->cf_ente);

		$copyObj->setFecha($this->fecha);

		$copyObj->setObservaciones($this->observaciones);

		$copyObj->setFechaEmision($this->fecha_emision);

		$copyObj->setCfGrupo($this->cf_grupo);

		$copyObj->setCfUsuario($this->cf_usuario);

		$copyObj->setEstatus($this->estatus);


		if ($deepCopy) {
									$copyObj->setNew(false);

			foreach($this->getTabDetallesOrdens() as $relObj) {
				$copyObj->addTabDetallesOrden($relObj->copy($deepCopy));
			}

		} 

		$copyObj->setNew(true);

		$copyObj->setNumOrden(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new TabOrdenesPeer();
		}
		return self::$peer;
	}

	
	public function initTabDetallesOrdens()
	{
		if ($this->collTabDetallesOrdens === null) {
			$this->collTabDetallesOrdens = array();
		}
	}

	
	public function getTabDetallesOrdens($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseTabDetallesOrdenPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collTabDetallesOrdens === null) {
			if ($this->isNew()) {
			   $this->collTabDetallesOrdens = array();
			} else {

				$criteria->add(TabDetallesOrdenPeer::CF_ORDEN, $this->getNumOrden());

				TabDetallesOrdenPeer::addSelectColumns($criteria);
				$this->collTabDetallesOrdens = TabDetallesOrdenPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(TabDetallesOrdenPeer::CF_ORDEN, $this->getNumOrden());

				TabDetallesOrdenPeer::addSelectColumns($criteria);
				if (!isset($this->lastTabDetallesOrdenCriteria) || !$this->lastTabDetallesOrdenCriteria->equals($criteria)) {
					$this->collTabDetallesOrdens = TabDetallesOrdenPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastTabDetallesOrdenCriteria = $criteria;
		return $this->collTabDetallesOrdens;
	}

	
	public function countTabDetallesOrdens($criteria = null, $distinct = false, $con = null)
	{
				include_once 'lib/model/om/BaseTabDetallesOrdenPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		$criteria->add(TabDetallesOrdenPeer::CF_ORDEN, $this->getNumOrden());

		return TabDetallesOrdenPeer::doCount($criteria, $distinct, $con);
	}

	
	public function addTabDetallesOrden(TabDetallesOrden $l)
	{
		$this->collTabDetallesOrdens[] = $l;
		$l->setTabOrdenes($this);
	}

} 